package com.wthink.hzgj.busInfo

import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.annotation.RequiresApi
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.Navigation
import androidx.navigation.findNavController
import com.wthink.hzgj.R
import com.wthink.hzgj.busInfo.viewmodel.BusInfoViewmodel
import com.wthink.hzgj.databinding.FragmentBusinfoBinding

class BusInfoFragment : Fragment(){

    private val viewModel by viewModels<BusInfoViewmodel>()

    private lateinit var binding: FragmentBusinfoBinding

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        binding = DataBindingUtil.inflate(
            inflater,
            R.layout.fragment_businfo,
            container,
            false
        )
        binding.viewModel = viewModel
        binding.lifecycleOwner = this

        return binding.root
    }

    @RequiresApi(Build.VERSION_CODES.O)
    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)

        binding.back.setOnClickListener {
            it.findNavController().popBackStack()
        }

        binding.settings.setOnClickListener {
            Navigation.findNavController(binding.main).navigate(R.id.busConfigFragment)
        }

        viewModel.queryBusInfo()
    }
}